/*
 * @Author: likaijie 847094299@qq.com
 * @Date: 2025-04-07 10:28:34
 * @LastEditors: likaijie 847094299@qq.com
 * @LastEditTime: 2025-04-07 10:28:52
 * @Description:
 */
import { http } from "@/utils/http";

/** 获取所有 API 提供商列表 */
export const getAllProviders = () => {
  return http.request<any>("get", "/api/admin/providers");
};

/** 获取 API 提供商使用情况 */
export const getProviderUsage = () => {
  return http.request<any>("get", "/api/admin/providers/usage");
};

/** 获取 API 提供商摘要信息 */
export const getProviderSummary = () => {
  return http.request<any>("get", "/api/admin/providers/summary");
};

/** 根据提供商查询余额 */
export const getProviderBalances = (params?: { provider?: string }) => {
  return http.request<any>("get", "/api/admin/providers/balances", {
    params
  });
};

/** 获取 API 提供商兼容性信息 */
export const getProviderCompatibility = () => {
  return http.request<any>("get", "/api/admin/providers/compatibility");
};

/** 切换指定服务类型的 API 提供商
 * @param serviceCode - 服务类型代码，如 "tg_live"、"ws_activate" 等
 * @param targetProvider - 目标 API 提供商名称，例如 "Apifox API提供商" 或 "TNT-PUB API提供商"
 */
export const switchServiceProvider = (
  serviceCode: string,
  targetProvider: string
) => {
  return http.request<any>(
    "put",
    `/api/admin/providers/services/${serviceCode}/switch`,
    {
      params: { targetProvider }
    }
  );
};

/** 设置指定服务类型的备选 API 提供商
 * @param serviceCode - 服务类型代码
 * @param fallbackServiceCode - 备选服务类型代码，通常为相同服务但不同提供商的标识
 */
export const setFallbackProvider = (
  serviceCode: string,
  fallbackServiceCode: string
) => {
  return http.request<any>(
    "put",
    `/api/admin/providers/services/${serviceCode}/fallback`,
    {
      params: { fallbackServiceCode }
    }
  );
};

/** 获取指定服务类型的参数映射信息 */
export const getParamMapping = (serviceCode: string) => {
  return http.request<any>(
    "get",
    `/api/admin/providers/services/${serviceCode}/param-mapping`
  );
};

/** 获取 API 提供商健康状态信息 */
export const getProvidersHealthCheck = () => {
  return http.request<any>("get", "/api/admin/providers/health-check");
};

/** 手动触发 API 提供商健康检查 */
export const triggerHealthCheck = () => {
  return http.request<any>("post", "/api/admin/providers/health-check");
};

/** 重置所有 API 提供商适配器的健康状态 */
export const resetHealth = () => {
  return http.request<any>("post", "/api/admin/providers/reset-health");
};
